#include <catch2/catch.hpp>

#include "solution.hpp"

using namespace solution_074;

TEST_CASE("074_search_a_2d_matrix", "[074]") {
    SECTION("example 1") {
        std::vector< std::vector<int> > matrix{{1,3,5,7},{10,11,16,20},{23,30,34,60}};
        CHECK(Solution().searchMatrixLinear(matrix, 3) == true);
        CHECK(Solution().searchMatrix(matrix, 3) == true);
    }

    SECTION("example 2") {
        std::vector< std::vector<int> > matrix{{1,3,5,7},{10,11,16,20},{23,30,34,60}};
        CHECK(Solution().searchMatrixLinear(matrix, 13) == false);
        CHECK(Solution().searchMatrix(matrix, 13) == false);
    }

    SECTION("example 3") {
        std::vector< std::vector<int> > matrix{{1,3}};
        CHECK(Solution().searchMatrixLinear(matrix, 3) == true);
        CHECK(Solution().searchMatrix(matrix, 3) == true);
    }

    SECTION("example 4") {
        std::vector< std::vector<int> > matrix{{1}};
        CHECK(Solution().searchMatrixLinear(matrix, 1) == true);
        CHECK(Solution().searchMatrix(matrix, 1) == true);
    }

    SECTION("example 5") {
        std::vector< std::vector<int> > matrix{{1},{3}};
        CHECK(Solution().searchMatrixLinear(matrix, 3) == true);
        CHECK(Solution().searchMatrix(matrix, 3) == true);
    }

    SECTION("example 6") {
        std::vector< std::vector<int> > matrix{{2,2,2},{2,2,2}};
        CHECK(Solution().searchMatrixLinear(matrix, 2) == true);
        CHECK(Solution().searchMatrix(matrix, 2) == true);
    }
}
